home *** CD-ROM | disk | FTP | other *** search
- /* strnicmp.c From TC Bible page 292 Use strncmp to compare a specified
- number of characters of two strings without regard to case */
-
- #include <stdio.h>
- #include <string.h>
- main()
- {
- int len, result;
- char str1[80], str2[80];
- printf("Enter a string: ");
- gets(str1);
- printf("Enter a string to compare with first: ");
- gets(str2);
- printf("How many characters to compare:");
- scanf(" %d", &len);
- printf("Based on case insensitive comparison of the first \
- %d characters\n", len);
- result = strnicmp(str1, str2, len);
- if (result == 0)
- {
- printf("\"%s\" == \"%s\"\n", str1, str2);
- }
- if (result < 0)
- {
- printf("\"%s\" < \"%s\"\n", str1, str2);
- }
- if (result > 0)
- {
- printf("\"%s\" > \"%s\"\n", str1, str2);
- }
- }